#include <Arduino.h>
#define TRIG 27
#define ECHO 21

// put function declarations here:
int myFunction(int, int);

void setup()
{
  // put your setup code here, to run once:
  Serial.begin(115200);
  pinMode(TRIG, OUTPUT);
  pinMode(ECHO, INPUT);
}

void loop()
{
  // put your main code here, to run repeatedly:
  // 产生一个10us的高脉冲去触发超声波
  digitalWrite(TRIG, HIGH);
  delayMicroseconds(10);
  digitalWrite(TRIG, LOW);
  double delta_time = pulseIn(ECHO, HIGH);            // 检测高电平持续时间，注意返回值，单位us
  float detect_distance = delta_time * 0.0343 / 2;    // 计算距离，单位cm,声速0.0343cm/us
  Serial.printf("distance=%f cm\n", detect_distance); // 输出距离
  delay(500);
}

// put function definitions here:
int myFunction(int x, int y)
{
  return x + y;
}